﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnergyIconController : MonoBehaviour
{
    private int maxCount;

    private int _Count;
    public int Count
    {
        get => _Count;
        set
        {
            if (value > maxCount) value = 3;
            else if (value < 0) value = 0;
            _Count = value;
            int i = 0;
            for (; i < value; i++)
            {
                Icons[i].Show();
            }
            for (; i < 3; i++)
            {
                Icons[i].Hide();
            }
        }
    }
    private Icon_Energy[] Icons;

    private void Awake()
    {
        Icons = GetComponentsInChildren<Icon_Energy>();
        maxCount = Character.MAXENERGY;
    }

    private void OnEnable()
    {
        Service.Get<EventSystem>().EnergyChange += OnEnergyChange;
    }
    private void OnDisable()
    {
        Service.Get<EventSystem>().EnergyChange -= OnEnergyChange;
    }

    private void OnEnergyChange(int shootCount)
    {
        Count = shootCount;
    }
}
